package com.sjmsks.Jpanels.work.shape;

import java.util.Arrays;
import java.util.NoSuchElementException;

// TODO 迭代器模式的实现
public class ShapeListIterator implements ShapeIterator {
	private int index;
	private AbstractShape[] shapeList;

	public ShapeListIterator(AbstractShape[] shapeList) {
		this.shapeList = shapeList;
		this.index = 0;
	}

	@Override
	public boolean hasNext() {
		return index < shapeList.length && shapeList[index] != null;
	}

	@Override
	public AbstractShape next() {
		if (!hasNext()) throw new NoSuchElementException();
		return shapeList[index++];
	}
}